/* GUI CONVERTED from sqqomt.p (converter v1.76) Mon Jul 22 11:50:38 2002 */
/* sqqomt.p - QUOTE MAINTENANCE                                               */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.40 $                                                          */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 4.0      LAST MODIFIED: 12/08/88   BY: jms *A548*                */
/* REVISION: 6.0      LAST MODIFIED: 03/20/90   BY: ftb *D011*                */
/* REVISION: 6.0      LAST MODIFIED: 03/22/90   BY: ftb *D013*                */
/* REVISION: 6.0      LAST MODIFIED: 03/22/90   BY: ftb *D007*                */
/* REVISION: 6.0      LAST MODIFIED: 04/09/90   BY: ftb *D002*                */
/* REVISION: 6.0      LAST MODIFIED: 05/22/90   BY: WUG *D022*                */
/* REVISION: 6.0      LAST MODIFIED: 06/29/90   BY: WUG *D043*                */
/* REVISION: 6.0      LAST MODIFIED: 08/09/90   BY: MLB *D055*                */
/* REVISION: 6.0      LAST MODIFIED: 08/29/90   BY: pml *D063*                */
/* REVISION: 6.0      LAST MODIFIED: 10/19/90   BY: pml *D109*                */
/* REVISION: 6.0      LAST MODIFIED: 12/21/90   BY: MLB *D238*                */
/* REVISION: 6.0      LAST MODIFIED: 03/13/91   BY: dld *D429*                */
/* REVISION: 6.0      LAST MODIFIED: 03/15/91   BY: afs *D438*                */
/* REVISION: 6.0      LAST MODIFIED: 07/22/91   BY: WUG *D781*                */
/* REVISION: 6.0      LAST MODIFIED: 08/14/91   BY: MLV *D825*                */
/* REVISION: 7.0      LAST MODIFIED: 09/17/91   BY: MLV *F015*                */
/* REVISION: 6.0      LAST MODIFIED: 10/01/91   BY: afs *D885*                */
/* REVISION: 7.0      LAST MODIFIED: 10/30/91   BY: MLV *F029*                */
/* REVISION: 7.0      LAST MODIFIED: 11/16/91   BY: pml *F048*                */
/* REVISION: 6.0      LAST MODIFIED: 11/18/91   BY: afs *D934*(rev only)      */
/* REVISION: 7.0      LAST MODIFIED: 01/22/92   BY: afs *F038*                */
/* REVISION: 7.0      LAST MODIFIED: 01/23/92   BY: afs *F039*                */
/* REVISION: 7.0      LAST MODIFIED: 01/24/92   BY: afs *F040*                */
/* REVISION: 7.0      LAST MODIFIED: 01/25/92   BY: afs *F042*                */
/* REVISION: 7.0      LAST MODIFIED: 02/21/92   BY: afs *F223*(rev only)      */
/* REVISION: 7.0      LAST MODIFIED: 03/06/92   BY: tjs *F247*(rev only)      */
/* REVISION: 7.0      LAST MODIFIED: 03/17/92   BY: tjs *F273*(rev only)      */
/* REVISION: 7.0      LAST MODIFIED: 03/26/92   BY: tmd *F324*                */
/* REVISION: 7.0      LAST MODIFIED: 03/27/92   BY: dld *F326*                */
/* REVISION: 7.0      LAST MODIFIED: 03/31/92   BY: afs *F338*                */
/* REVISION: 7.0      LAST MODIFIED: 04/02/92   BY: afs *F253*                */
/* REVISION: 7.0      LAST MODIFIED: 04/02/92   BY: dld *F349*                */
/* REVISION: 7.0      LAST MODIFIED: 04/08/92   BY: tmd *F367*(rev only)      */
/* REVISION: 7.0      LAST MODIFIED: 04/06/92   BY: dld *F358*(rev only)      */
/* REVISION: 7.0      LAST MODIFIED: 04/09/92   BY: afs *F356*                */
/* REVISION: 7.0      LAST MODIFIED: 04/16/92   BY: dld *F382*(rev only)      */
/* REVISION: 7.0      LAST MODIFIED: 04/22/92   BY: tjs *F421*(rev only)      */
/* REVISION: 7.0      LAST MODIFIED: 05/01/92   BY: tjs *F464*(rev only)      */
/* REVISION: 7.0      LAST MODIFIED: 06/16/92   BY: afs *F519*(rev only)      */
/* REVISION: 7.0      LAST MODIFIED: 06/19/92   BY: tmd *F458*                */
/* REVISION: 7.0      LAST MODIFIED: 06/26/92   BY: afs *F676*(rev only)      */
/* REVISION: 7.0      LAST MODIFIED: 06/26/92   BY: afs *F710*(rev only)      */
/* REVISION: 7.0      LAST MODIFIED: 06/30/92   BY: tjs *F698*                */
/* REVISION: 7.0      LAST MODIFIED: 07/07/92   BY: tjs *F496*(rev only)      */
/* REVISION: 7.0      LAST MODIFIED: 07/09/92   BY: MLV *F458*(TMD CONT)      */
/* REVISION: 7.0      LAST MODIFIED: 07/22/92   BY: tjs *F800*(rev only)      */
/* REVISION: 7.0      LAST MODIFIED: 08/13/92   BY: tjs *F835*(rev only)      */
/* REVISION: 7.3      LAST MODIFIED: 09/22/92   BY: tjs *G035*                */
/* REVISION: 7.3      LAST MODIFIED: 09/23/92   BY: tjs *G085*                */
/* REVISION: 7.3      LAST MODIFIED: 09/29/92   BY: tjs *G086*(rev only)      */
/* REVISION: 7.3      LAST MODIFIED: 10/08/92   BY: mpp *G128*(rev only)      */
/* REVISION: 7.3      LAST MODIFIED: 09/27/92   BY: jcd *G247*                */
/* REVISION: 7.3      LAST MODIFIED: 11/03/92   BY: sas *G242*(rev only)      */
/* REVISION: 7.3      LAST MODIFIED: 11/19/92   BY: tjs *G191*(rev only)      */
/* REVISION: 7.3      LAST MODIFIED: 12/01/92   BY: tjs *G379*                */
/* REVISION: 7.3      LAST MODIFIED: 12/15/92   BY: afs *G447*                */
/* REVISION: 7.3      LAST MODIFIED: 12/18/92   BY: tjs *G456*(rev only)      */
/* REVISION: 7.3      LAST MODIFIED: 12/21/92   BY: tjs *G461*                */
/* REVISION: 7.3      LAST MODIFIED: 12/21/92   BY: mpp *G485*                */
/* REVISION: 7.3      LAST MODIFIED: 01/12/93   BY: tjs *G507*(rev only)      */
/* REVISION: 7.3      LAST MODIFIED: 01/13/93   BY: tjs *G522*(rev only)      */
/* REVISION: 7.3      LAST MODIFIED: 01/15/93   BY: afs *G501*                */
/* REVISION: 7.3      LAST MODIFIED: 01/21/93   BY: tjs *G579*(rev only)      */
/* REVISION: 7.3      LAST MODIFIED: 01/26/93   BY: bcm *G429*                */
/* REVISION: 7.3      LAST MODIFIED: 01/27/93   BY: bcm *G414*                */
/* REVISION: 7.3      LAST MODIFIED: 02/02/93   BY: mpp *G626*                */
/* REVISION: 7.3      LAST MODIFIED: 02/03/93   BY: tjs *G620*(rev only)      */
/* REVISION: 7.3      LAST MODIFIED: 02/08/93   BY: tjs *G651*                */
/* REVISION: 7.3      LAST MODIFIED: 02/10/93   BY: tjs *G588*(rev only)      */
/* REVISION: 7.3      LAST MODIFIED: 02/17/93   BY: bcm *G691*                */
/* REVISION: 7.3      LAST MODIFIED: 02/18/93   BY: afs *G692*                */
/* REVISION: 7.3      LAST MODIFIED: 03/16/93   BY: bcm *G823*(rev only)      */
/* REVISION: 7.3      LAST MODIFIED: 03/31/93   BY: bcm *G889*(rev only)      */
/* REVISION: 7.3      LAST MODIFIED: 04/08/93   BY: tjs *G830*(rev only)      */
/* REVISION: 7.3      LAST MODIFIED: 04/26/93   BY: bcm *GA36*(rev only)      */
/* REVISION: 7.3      LAST MODIFIED: 04/30/93   BY: ksp *GA60*                */
/* REVISION: 7.3      LAST MODIFIED: 05/18/93   BY: jjs *GB12*                */
/* REVISION: 7.3      LAST MODIFIED: 05/20/93   BY: kgs *GA92*                */
/* REVISION: 7.3      LAST MODIFIED: 05/20/93   BY: kgs *GB18*(rev only)      */
/* REVISION: 7.3      LAST MODIFIED: 05/28/93   BY: afs *GB31*                */
/* REVISION: 7.4      LAST MODIFIED: 06/07/93   BY: wep *H005*                */
/* REVISION: 7.4      LAST MODIFIED: 07/02/93   BY: wep *H016*(rev only)      */
/* REVISION: 7.4      LAST MODIFIED: 07/21/93   BY: dpm *H023*(rev only)      */
/* REVISION: 7.4      LAST MODIFIED: 08/23/93   BY: cdt *H049*                */
/* REVISION: 7.4      LAST MODIFIED: 09/29/93   BY: tjs *H082*                */
/* REVISION: 7.4      LAST MODIFIED: 09/28/93   BY: cdt *H086*                */
/* REVISION: 7.4      LAST MODIFIED: 10/19/93   BY: bcm *H185*                */
/* REVISION: 7.4      LAST MODIFIED: 10/19/93   BY: cdt *H184*                */
/* REVISION: 7.4      LAST MODIFIED: 11/22/93   BY: afs *H238*(rev only)      */
/* REVISION: 7.4      LAST MODIFIED: 03/09/94   BY: cdt *H292*                */
/* REVISION: 7.4      LAST MODIFIED: 03/29/94   BY: dpm *GJ13*                */
/* REVISION: 7.4      LAST MODIFIED: 04/21/94   BY: dpm *GJ49*                */
/* REVISION: 7.4      LAST MODIFIED: 05/23/94   BY: afs *FM85*                */
/* REVISION: 7.4      LAST MODIFIED: 05/26/94   BY: afs *GH40*                */
/* REVISION: 7.4      LAST MODIFIED: 06/01/94   BY: afs *GK04*                */
/* REVISION: 7.4      LAST MODIFIED: 07/08/94   BY: bcm *H437*                */
/* REVISION: 7.4      LAST MODIFIED: 07/19/94   BY: qzl *H446*                */
/* REVISION: 7.4      LAST MODIFIED: 09/15/94   by: slm *GM62*                */
/* REVISION: 7.4      LAST MODIFIED: 09/22/94   BY: jpm *GM78*                */
/* REVISION  7.4      LAST MODIFIED: 10/29/94   BY: bcm *FT06*                */
/* REVISION  7.4      LAST MODIFIED: 11/06/94   BY: rwl *GO31*                */
/* REVISION: 8.5      LAST MODIFIED: 11/29/94   BY: mwd *J034*                */
/* REVISION: 7.2      LAST MODIFIED: 01/12/95   BY: ais *F0C7*                */
/* REVISION: 8.5      LAST MODIFIED: 03/21/95   BY: jlf *J042*                */
/* REVISION: 7.4      LAST MODIFIED: 12/07/95   BY: rxm *H0FS*                */
/* REVISION: 7.4      LAST MODIFIED: 03/29/95   BY: dzn *F0PN*                */
/* REVISION: 8.5      LAST MODIFIED: 07/06/95   BY: taf *J053*                */
/* REVISION: 8.5      LAST MODIFIED: 04/10/96   BY: DAH *J0HR*                */
/* REVISION: 7.4      LAST MODIFIED: 05/13/96   BY: tzp *G1V8*                */
/* REVISION: 8.5      LAST MODIFIED: 05/28/96   BY: gwm *J0NF*                */
/* REVISION: 8.5      LAST MODIFIED: 08/03/96   BY: ajw *J12Q*                */
/* REVISION: 8.5      LAST MODIFIED: 08/06/97   BY: *J1YG* Seema Varma        */
/* REVISION: 8.6      LAST MODIFIED: 11/18/97   BY: *J25B* Aruna Patil        */
/* REVISION: 8.6      LAST MODIFIED: 11/18/97   BY: *K1BG* Aruna Patil        */
/* REVISION: 8.6      LAST MODIFIED: 12/08/97   BY: *K1BP* Val Portugal       */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* Annasaheb Rahane   */
/* REVISION: 8.6E     LAST MODIFIED: 04/15/98   BY: *L00L* LN/SVA             */
/* REVISION: 8.6E     LAST MODIFIED: 05/08/98   BY: *L00W* ED v.d.Gevel RO    */
/* REVISION: 8.6E     LAST MODIFIED: 05/11/98   BY: *J2L3* Niranjan Ranka     */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan         */
/* REVISION: 9.0      LAST MODIFIED: 11/24/98   BY: *M017* David Morris       */
/* REVISION: 9.0      LAST MODIFIED: 02/24/99   BY: *M094* Jean Miller        */
/* REVISION: 9.0      LAST MODIFIED: 03/13/99   BY: *M0BD* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 07/24/00   BY: *J3Q2* Ashwini Ghaisas    */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KN* Mark Brown         */
/* REVISION: 9.1      LAST MODIFIED: 11/19/00   BY: *M0WC* Rajesh Thomas      */
/* REVISION: 9.1      LAST MODIFIED: 12/18/00   BY: *M0TZ* Veena Lad          */
/* Revision: 1.30          BY: Katie Hilbert      DATE: 04/01/01  ECO: *P002* */
/* Revision: 1.31          BY: Anil Sudhakaran    DATE: 06/11/01  ECO: *M19V* */
/* Revision: 1.32          BY: Santhosh Nair      DATE: 03/05/02  ECO: *M1H1* */
/* Revision: 1.33          BY: Ashish Maheshwari  DATE: 05/14/02  ECO: *P06M* */
/* Revision: 1.34          BY: Ashish Maheshwari  DATE: 05/20/02  ECO: *P04J* */
/* Revision: 1.38          BY: Dave Caveney       DATE: 06/04/02  ECO: *P042* */
/* Revision: 1.39          BY: Samir Bavkar       DATE: 07/07/02  ECO: *P0B0* */
/* $Revision: 1.40 $       BY: Robin McCarthy     DATE: 07/15/02  ECO: *P0BJ* */

/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* Revision: 9.1      LAST MODIFIED: 28/10/03   BY: *cli* cli   SPEC: HK-S-014*/


/* DISPLAY TITLE */
{mfdtitle.i "2+ "}
{apconsdf.i}   /* PRE-PROCESSOR CONSTANTS FOR LOGISTICS ACCOUNTING */

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE sqqomt_p_1 "Display Weights"
/* MaxLen: Comment: */

&SCOPED-DEFINE sqqomt_p_2 "Promise Date"
/* MaxLen: Comment: */

&SCOPED-DEFINE sqqomt_p_5 "Line Pricing"
/* MaxLen: Comment: */

&SCOPED-DEFINE sqqomt_p_7 "Comments"
/* MaxLen: Comment: */

&SCOPED-DEFINE sqqomt_p_8 "Calc Freight"
/* MaxLen: Comment: */

&SCOPED-DEFINE sqqomt_p_9 "Reprice"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

define new shared variable oldcurr like qo_curr.
define new shared variable rndmthd like rnd_rnd_mthd.
define new shared variable line like qod_line.
define new shared variable del-yn like mfc_logical.
define new shared variable qty_req like in_qty_req.
define new shared variable prev_due like qod_due_date.
define new shared variable prev_qty_ord like qod_qty_quot.
define new shared variable trnbr like tr_trnbr.
define new shared variable qty as decimal.
define new shared variable part as character format "x(18)".
define new shared variable sngl_ln like soc_ln_fmt.
define new shared variable qo_recno as recid.
define new shared variable cm_recno as recid.
define new shared variable cmtindx like cmt_indx.
define new shared variable promise_date as date label {&sqqomt_p_2}.
define new shared variable rsn_lost like qod_rsn_lost.
define new shared variable qonbr like qo_nbr.
define new shared variable qoclcmmts like mfc_logical.
define new shared variable qocmmts like mfc_logical
   initial yes label {&sqqomt_p_7}.
define new shared variable new_order like mfc_logical initial no.
define new shared variable qotax_trl like tax_trl.
define new shared variable tax_in like cm_tax_in.
define new shared variable avail_calc as integer.
define new shared variable so_db like dc_name.
define new shared variable inv_db like dc_name.
define buffer bill_cm for cm_mstr.
define new shared variable mult_slspsn like mfc_logical no-undo.
define new shared variable tax_recno as recid.
define new shared variable ad_recno as recid.
define new shared variable ship2_addr like so_ship.
define new shared variable ship2_pst_id like cm_pst_id.
define new shared variable ship2_lang like cm_lang.
define new shared variable ship2_ref like cm_addr.
define new shared variable freight_ok like mfc_logical.
define new shared variable old_ft_type like ft_type.
define new shared variable calc_fr like mfc_logical
   label {&sqqomt_p_8}.
define new shared variable undo_cust like mfc_logical.
define new shared variable undo_flag like mfc_logical.
define new shared variable disp_fr like mfc_logical
   label {&sqqomt_p_1}.
define new shared variable display_trail like mfc_logical initial yes.
define new shared variable calc_open_qty like mfc_logical initial no.
define new shared variable qoc_pc_line like mfc_logical initial yes.
define new shared frame b1.
define new shared variable qocrt_int like qod_crt_int.
define new shared variable picust like cm_addr.
define new shared variable price_changed like mfc_logical.
define new shared variable line_pricing like pic_qo_linpri
   label {&sqqomt_p_5}.
define new shared variable reprice like mfc_logical label {&sqqomt_p_9}
   initial no.
define new shared variable qod_recno as recid.
define new shared variable balance_fmt as character.
define new shared variable limit_fmt as character.
define new shared variable prepaid_fmt as character no-undo.
define new shared variable prepaid_old as character no-undo.

define variable tax_date like tax_effdate.
define variable comment_type like so_lang.
define variable undomain as logical no-undo.
define variable next_undomain as logical no-undo.
define variable nextmain as logical no-undo.
define variable use-log-acctg as logical no-undo.
define variable lv_shipfrom as character no-undo.

define new shared frame a.
define new shared frame sold_to.
define new shared frame ship_to.
define new shared frame b.

{pppivar.i "new"}  /*Pricing variables*/

/*DEFINE WORKFILE FOR QTY ACCUM USED BY BEST PRICING ROUTINES*/
{pppiwqty.i "new" }

define new shared variable cfexists    like mfc_logical.
define new shared variable cf_cfg_path like mfc_char.
define new shared variable cf_cfg_suf  like mfc_char.
define new shared variable cf_chr        as character.
define new shared variable cf_cfg_strt_err like mfc_logical.
define variable cf_default_model as character.
define new shared variable phCfcfstrt as handle no-undo.
define new shared variable phCfEvents as handle no-undo.
define new shared variable CtrlFrame as widget-handle no-undo.
define variable cf_exe_loc as character.
define variable err-stat as integer.
define variable checkwritepath as character.
define variable testfile as character.
define new shared variable calicodone like mfc_logical.
define variable l_qo_fix_pr like mfc_logical no-undo.

define variable minmaxerr like mfc_logical no-undo.
/*cli*/ define variable nrm-seq-num like so_nbr init "".
/*cli*/ define variable nrmnbr     like nr_seqid. 
/*cli*/ define new shared variable qosite     like qo_site. 


/*THIS TEMP TABLE IS CREATED TO CALCULATE FREIGHT CHARGES  */
/*WHEN A NEW SALES QUOTE LINE IS ADDED TO AN EXISTING QUOTE*/
/*WHEN THE FREIGHT TYPE IS "INCLUDE".                      */
define new shared temp-table l_fr_table
       field l_fr_qodnbr  like qod_nbr
       field l_fr_qodline like qod_line
       field l_fr_chrg    like qod_fr_chg
       field l_qodlist_pr like qod_list_pr
       index nbrline is primary l_fr_qodnbr l_fr_qodline.

{gptxcdec.i}    /* DECLARATIONS FOR gptxcval.i */

/* TEMP TABLE DEFINITIONS FOR APM/API */
{ifttcmdr.i "new"}
{ifttcmdv.i "new"}

{lafrttmp.i "new"}   /* FREIGHT ACCRUAL TEMP TABLE DEFINITION */

{etdcrvar.i "new"}
{etvar.i &new="new"}
{etrpvar.i &new="new"}
{mfsqtrla.i "NEW"}

{sqqomt01.i}    /* FORM DEFINITION FOR FRAME D */
/* Check for existence of configurator control record*/
{gprun.i ""cfctrl.p"" "(""cf_w_mod"", output cfexists)"}
/*GUI*/ if global-beam-me-up then undo, leave.


if cfexists then do:
    /* Determine Unix or Windows path format based on user O/S */
    /* For Windows users, 'opsys' responds with 'msdos' */
    /* on Pro 8.1 and 'WIN32' on Progress 8.2  */
    /* Progress 8.2 is 32-bit only - Win95 and NT */
    /* Even a Unix user can delete a quote and must have access to */
    /* the configuration files so that these are deleted with the */
    /* quote lines.                                                */
   if opsys = "msdos" or opsys = "WIN32" then do:
      cf_chr = "~\".
      /* Get the Windows path of the quote configuration files*/
      find mfc_ctrl where mfc_field = "cf_w_qo_cfg" no-lock no-error.
      if available mfc_ctrl then cf_cfg_path = mfc_char.
   end.
   else do:
      cf_chr = "/".
      /* Get the unix path of the concinity quote files */
      find mfc_ctrl where mfc_field = "cf_u_qo_cfg" no-lock no-error.
      if available mfc_ctrl then cf_cfg_path = mfc_char.
   end.

   /* Validate that the path is accessible*/
   cf_cfg_strt_err = no.
   output to "cf_test.txt".
   display getTermLabel("DELETE_IF_FOUND",20) format "x(20)".
   output close.
   checkwritepath = cf_cfg_path + cf_chr + "cf_test.txt".
   testfile = search("cf_test.txt").
   if testfile <> ? then do:
      os-copy value(testfile) value(checkwritepath).
      err-stat = os-error.
      if err-stat = 0 then do:
         os-delete value(checkwritepath).
         err-stat = os-error.
      end.
      else err-stat = 1.
   end.
   else err-stat = 1.

   /*Determine if the user is able to run Concinity:  running */
   /*Progress 8.2+, running on Win95 or NT, and access to the */
   /*Concinity executable. */
   if cf_cfg_strt_err = no then do:
      cf_cfg_strt_err = yes.

      if (substring(proversion,1,1) = "8" and
         substring(proversion,3,1) >= "2" ) or
         substring(proversion,1,1) = "9" then do:
         if opsys = "WIN32" then do:
            /* Get the location of Concinity executable*/
            find mfc_ctrl where mfc_field = "cf_w_exe" no-lock no-error.
            if available mfc_ctrl then cf_exe_loc = mfc_char.
            if cf_exe_loc <> "" and search(cf_exe_loc) <> ? then do:
               if err-stat = 0 then do:
                  /* The conditions to run Concinity have been met */
                  cf_cfg_strt_err = no.
                  /* OK to start Concinity, get the default model*/
                  find mfc_ctrl where mfc_field = "cf_model"
                     no-lock no-error.
                  if available mfc_ctrl then cf_default_model = mfc_char.
                  /* Launch Calico */
                       
                  {gprunmo.i &module  = "cf" &program = "cfcfstrt.p"
                     &param   = """(cf_default_model) """
                     &persistent = ""persistent set phCfcfstrt""
                  }
                    
                  if cf_cfg_strt_err then do:
                     /* An error was discovered in trying to start Concinity */
                     {pxmsg.i &MSGNUM=1829 &ERRORLEVEL=4}
                     /* Concinity is unavailable */
                     delete PROCEDURE phCfcfstrt no-error.
                  end.
               end. /* if err-stat... */
               /* We only need to tell the user that the location is not  */
               /* accessible after we know he/she is a Concinity user */
               else do:
                  if err-stat <> 0 then do:
                     {pxmsg.i &MSGNUM=2003 &ERRORLEVEL=2}
                     /* Configuration location is inaccessible */
                     pause.
                     cf_cfg_strt_err = yes.
                  end.
               end. /* end else if err-stat... */
            end. /* if cf_exe_loc... */
         end. /* if opsys... */
      end. /* if proversion... */
   end. /* if cf_cfg_strt_err... */
   /* The cf_cfg_strt_err variable is used throughout the process to */
   /* determine if Concinity is running.(no = no error,it's running )*/
   /* Get the quote suffix from the control file*/
   find mfc_ctrl where mfc_field = "cf_qo_suf" no-lock no-error.
   if available mfc_ctrl then cf_cfg_suf = mfc_char.
end. /* if cf_exists... */

/* ASSIGN ORIGINAL FORMAT TO _OLD VARIABLES */
assign
   nontax_old = nontaxable_amt:format
   taxable_old = taxable_amt:format
   line_tot_old = line_total:format
   disc_old     = disc_amt:format
   trl_amt_old = qo_trl1_amt:format
   tax_amt_old = tax_amt:format
   ord_amt_old = ord_amt:format
   prepaid_old = qo_prepaid:format.

oldcurr = "".

limit_fmt = "->>>>,>>>,>>9.99".
/* SET LIMIT_FMT BASED ON BASE CURR ROUND METHOD */
{gprun.i ""gpcurfmt.p"" "(input-output limit_fmt,
                          input gl_rnd_mthd)"}
/*GUI*/ if global-beam-me-up then undo, leave.

balance_fmt = "->>>>,>>>,>>9.99".
/* SET BALANCE_FMT BASED ON BASE CURR ROUND METHOD */
{gprun.i ""gpcurfmt.p"" "(input-output balance_fmt,
                          input gl_rnd_mthd)"}
/*GUI*/ if global-beam-me-up then undo, leave.


do transaction on error undo, retry:
   find first qoc_ctrl no-lock no-error.
   if not available qoc_ctrl then do:
      create qoc_ctrl.
      if recid(qoc_ctrl) = -1 then .
   end.
   assign
      qocmmts = qoc_hcmmts
      sngl_ln = qoc_ln_fmt
      qoclcmmts = qoc_lcmmts.
end.

do transaction on error undo, retry:
   /* SET UP PRICING BY LINE VALUES */
   find first mfc_ctrl where mfc_field = "qoc_pc_line"
      no-lock  no-error.
   if available mfc_ctrl then
      qoc_pc_line = mfc_logical.
end.

/*  Determine and store the way qty avail to alloc is calculated */
/*  The resulting setting will match the first field in sosopm.p */
find first soc_ctrl no-lock.
if soc_all then do:
   if soc_on_ord then avail_calc = 2.
   else avail_calc = 1.
end.
else if soc_req then do:
   if soc_on_ord then avail_calc = 4.
   else avail_calc = 3.
end.

so_db = global_db.

do transaction on error undo, retry:
   find first pic_ctrl no-lock no-error.
   if not available pic_ctrl then
      create pic_ctrl.
end.

mainloop:
repeat:
/*GUI*/ if global-beam-me-up then undo, leave.

   find first qoc_ctrl no-lock.
   comment_type = global_type.

   /* DISPLAY SELECTION FORM */

   /* Forms for frames a and b moved to sqqomt02.i. */
   /* Form for frame c moved to sqqomt02.i. and included in frame b1 */
   /* Include file moved here to limit the scope of frames to the    */
   /* transaction block                                              */
   {sqqomt02.i}   /* Form definitions for shared frames a,b, and b1  */

   {mfadform.i "sold_to" 1 SOLD-TO}
   /*V8+*/
         {mfadform.i "ship_to" "41" SHIP-TO}   

   find first gl_ctrl no-lock.

         hide all no-pause.   

   cr_terms_changed = no.

   /*GUI: view frame dtitle. */
IF global-tool-bar AND global-tool-bar-handle ne ? THEN
  view global-tool-bar-handle. /*GUI*/

   view frame a.
   view frame sold_to.
   view frame ship_to.
   view frame b.

   prompt-for qo_nbr with frame a
   editing:

      if keyfunction(lastkey) = "RECALL" or lastkey = 307
         then display qonbr @ qo_nbr with frame a.

      /* FIND NEXT/PREVIOUS RECORD */
      {mfnp.i qo_mstr qo_nbr qo_nbr qo_nbr qo_nbr qo_nbr}

      if recno <> ? then do:
         if qo__qad03 = 2 then
            assign l_qo_fix_pr = yes.
         else
         if qo__qad03 = 1 then
            assign l_qo_fix_pr = no.
         else
         if qo__qad03 = 0 then
            assign l_qo_fix_pr = qo_fix_rate.

         {mfaddisp.i qo_cust sold_to}
         {mfaddisp.i qo_ship ship_to}
         display qo_nbr qo_cust qo_bill qo_ship with frame a.
         find first qod_det where qod_nbr = qo_nbr
            no-lock no-error.
         if available qod_det then
            rsn_lost = qod_rsn_lost.
         else
            rsn_lost = " ".

         if qo_slspsn[2] <> "" or
            qo_slspsn[3] <> "" or
            qo_slspsn[4] <> "" then mult_slspsn = true.
         else mult_slspsn = false.

         find cm_mstr where cm_mstr.cm_addr = qo_cust no-lock.
         if qo_cust <> qo_ship and
            can-find(cm_mstr where cm_mstr.cm_addr = qo_ship) then
            find cm_mstr where cm_mstr.cm_addr = qo_ship no-lock.

         find ct_mstr where ct_code = qo_cr_terms no-lock no-error.
         if available ct_mstr then qocrt_int = ct_terms_int.
         {sqqomtdi.i} /* Display qo_ord_date, etc in frame b */
      end.
   end.

   do transaction on error undo, retry:
      if input qo_nbr = "" then do:
/*GUI*/ if global-beam-me-up then undo, leave.

/*cli**  Begin ***** Generate a new Sales Quotation Number from NRM *****/ 

         prompt-for qo_site with frame c row 8 center overlay THREE-D .
         assign qosite = input qo_site.

         {gprun.i ""gpsiver.p""
         "(input qosite, input ?, output return_int)"}
/*GUI*/  if global-beam-me-up then undo, leave.

         if return_int = 0 then do:
            /* User does not have access to default site # */
            {pxmsg.i &MSGNUM=2711 &ERRORLEVEL=2 &MSGARG1=qosite}
            pause.
            undo, retry.
         end.
         find first nrs_mstr where nrs_site = input qo_site and 
              nrs_sqnbr <> "" no-lock no-error.
         if available nrs_mstr then do:  
             assign nrmnbr = nrs_sqnbr
                    nrm-seq-num = "".  
               {gprunp.i "xxnrm" "p" "nr_dispense"
               "(input nrmnbr,
               input TODAY,
               output nrm-seq-num)"}
             if nrm-seq-num = "" then
         /* Get next quote number with prefix */
             {mfnctrlc.i qoc_ctrl qoc_qo_pre qoc_qo qo_mstr qo_nbr qonbr}
/*GUI*/  if global-beam-me-up then undo, leave.
         end.
         else 
             /* GET NEXT SALES ORDER NUMBER WITH PREFIX */
             {mfnctrlc.i soc_ctrl soc_so_pre soc_so so_mstr so_nbr sonbr}
/*GUI*/  if global-beam-me-up then undo, leave.
         

/*cli******* Generate a new Sales Quotation Number from NRM ************/

/*cli         /* Get next quote number with prefix */
         {mfnctrlc.i qoc_ctrl qoc_qo_pre qoc_qo qo_mstr qo_nbr qonbr}
*/     
      end.
      else
         qonbr = input qo_nbr.

   end.
/*GUI*/ if global-beam-me-up then undo, leave.
  /* DO TRANSACTION ON ERROR UNDO.. */

/*cli*/ if nrm-seq-num <> "" then
/*cli*/    assign qonbr = nrm-seq-num.


   assign undomain = false
      next_undomain = false
      nextmain = false.

   /* CHECK IF LOGISTICS ACCOUNTING IS ENABLED */
   {gprun.i ""lactrl.p"" "(output use-log-acctg)"}
/*GUI*/ if global-beam-me-up then undo, leave.

/*cli {gprun.i ""sqqomta1.p""
      "(output undomain,
        output next_undomain,
        output nextmain)"}
cli*/

/*cli*/{gprun.i ""xxsqqomta1.p""
      "(output undomain,
        output next_undomain,
        output nextmain)"}

/*GUI*/ if global-beam-me-up then undo, leave.


   if undomain then undo mainloop.
   if next_undomain then undo mainloop, next mainloop.
   if nextmain then next mainloop.

   do transaction:
      find qo_mstr where recid(qo_mstr) = qo_recno exclusive-lock.
   end.

   /*INITIALIZE QTY ACCUMULATION WORKFILES USED BY BEST PRICING*/
   {gprun.i ""gppiqty1.p"" "(""2"",
                                   qo_mstr.qo_nbr,
                                   yes,
                                   yes)"}
/*GUI*/ if global-beam-me-up then undo, leave.


   hide frame sold_to no-pause.
   hide frame ship_to no-pause.

   hide frame b1 no-pause.
   hide frame a no-pause.

   /* LINE ITEMS */
   hide frame a.
   {gprun.i ""sqqomta.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


   /* IF LOGISTICS ACCOUNTING IS ENABLED AND VALID FREIGHT TERMS/LIST IS     */
   /* ENTERED DISPLAY THE LOGISTICS CHARGE DETAIL FRAME WHICH DISPLAYS THE   */
   /* DEFAULT LOGISTICS SUPPLIER FOR THIS ORDER WHICH CAN BE UPDATED IN THIS */
   /* FRAME. NOTE: A CORRESPONDING lacd_det RECORD IS CREATED AND THIS       */
   /* LOGISTICS SUPPLIER IS STORED THERE.                                    */

   if use-log-acctg and
      qo_fr_terms <> "" and
      (can-find(first qod_det where qod_nbr = qo_nbr and qod_fr_list <> ""))
   then do transaction on error undo, retry:

      for first ft_mstr
      fields (ft_lc_charge ft_accrual_level)
      where ft_terms = qo_fr_terms
      no-lock:
      end. /* FOR FIRST FT_MSTR */

      if    available ft_mstr
        and (    ft_accrual_level = {&LEVEL_Shipment}
              or ft_accrual_level = {&LEVEL_Line}
            )
        then do:

         for first qod_det
         fields (qod_nbr qod_site)
         where qod_nbr = qo_nbr
         no-lock:
            lv_shipfrom = qod_site.
         end.

         if    ft_accrual_level = {&LEVEL_Shipment}
           and qo_site <> ""
           then
            lv_shipfrom = qo_site.

         view frame a.

         /* ASSIGN LOGISTICS SUPPLIER */
         {gprunmo.i  &module = "LA" &program = "laosupp.p"
                     &param  = """(input 'ADD',
                                   input '{&TYPE_Quote}',
                                   input qo_nbr,
                                   input lv_shipfrom,
                                   input ft_lc_charge,
                                   input ft_accrual_level,
                                   input yes,
                                   input yes)"""}
      end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* IF AVAILABLE FT_MSTR AND ... */

   end.   /* TRANSACTION */

   /*TEST FOR AT END OF ORDER PRICING OR REPRICING REQUIREMENTS
   AND SUBSEQUENT PROCESSING OF SUCH*/
   if new_order and not line_pricing then do:
      /*ALL LINES NEED TO BE PRICED, ENTERED PRICES WILL BE RETAINED*/
      for each qod_det where qod_nbr = qo_mstr.qo_nbr no-lock:
/*GUI*/ if global-beam-me-up then undo, leave.

         qod_recno = recid(qod_det).
         /*TRANSACTION HISTORY WILL BE REWRITTEN WITH REVISED PRICE*/
         do transaction on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

            {gprun.i ""sqqoprln.p"" "(yes,
                                      yes,
                                      yes,
                                      yes,
                                      output minmaxerr)"}
/*GUI*/ if global-beam-me-up then undo, leave.

            qo_priced_dt = today.
         end.
/*GUI*/ if global-beam-me-up then undo, leave.

      end.
/*GUI*/ if global-beam-me-up then undo, leave.

   end.

   if reprice or new_order then do:
      price_changed = no.
      /*CHECK REPRICE TABLE TO DETERMINE WHICH LINES REQUIRE REPRICING*/
      for each wrep_wkfl where wrep_parent and
            wrep_rep
            no-lock:
/*GUI*/ if global-beam-me-up then undo, leave.

         find qod_det where qod_nbr  = qo_mstr.qo_nbr and
            qod_line = wrep_line
            no-lock no-error.
         if available qod_det then do:
            qod_recno = recid(qod_det).
            do transaction on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

               {gprun.i ""sqqoprln.p"" "(yes,
                                         yes,
                                         no,
                                         yes,
                                         output minmaxerr)"}
/*GUI*/ if global-beam-me-up then undo, leave.


               qo_priced_dt = today.
            end.
/*GUI*/ if global-beam-me-up then undo, leave.

         end.
      end.
/*GUI*/ if global-beam-me-up then undo, leave.

      if price_changed then do:
         {gprun.i ""sqphdp.p""}
/*GUI*/ if global-beam-me-up then undo, leave.
 /*RE-DISPLAY LINE ITEMS*/
      end.
   end.

   /* SET CREDIT & FREIGHT TERMS FIELDS */
   do transaction on error undo, retry:

      if current_cr_terms <> "" and current_cr_terms <> qo_cr_terms
      then
      assign
         cr_terms_changed = yes
         qo_cr_terms = current_cr_terms.
      if current_fr_terms <> ""
         and qo_manual_fr_terms = no
      then
         qo_fr_terms = current_fr_terms.
      assign
         current_cr_terms = ""
         current_fr_terms = ""
         .
   end.

   view frame a.
   display qo_ship with frame a.

   do transaction on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

      /* INITIALIZE TRAILER CODES FROM CONTROL FILE FOR NEW ORDERS ONLY */
      {gpgettrl.i &hdr_file="qo" &ctrl_file="soc"}
      if new_order
         and soc_use_frt_trl_cd
      then do:
         for first fr_mstr
            fields (fr_curr fr_list fr_site fr_trl_cd)
            where   fr_list = qo_fr_list
                and fr_site = qo_site
                and fr_curr = qo_curr
            no-lock:
         end. /* FOR FIRST fr_mstr */

         if available fr_mstr
         then
            qo_trl1_cd = fr_trl_cd.

      end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* IF new-order and ... */

      /* CALCULATE FREIGHT */
      if calc_fr and qo_fr_terms = "" then do:
         /* INVALID FREIGHT TERMS */
         {mfmsg03.i 671 2 qo_fr_terms """" """"}
      end. /* IF CALC_FR AND SO_FR_TERMS */

      if calc_fr and qo_fr_terms <> "" then do:
         {gprun.i ""sqfrcalc.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


         if use-log-acctg then do:
            /* CREATE TAX RECORDS FOR FREIGHT ACCRUAL */
            {gprunmo.i  &module = "LA" &program = "lafrtax.p"
                        &param  = """(input qo_site,
                                      input '{&TYPE_Quote}',
                                      input (if qo_tax_date <> ? then
                                                qo_tax_date
                                             else if qo_due_date <> ? then
                                                qo_due_date
                                             else qo_ord_date),
                                      input (if qo_due_date <> ? then
                                                qo_due_date
                                             else qo_ord_date),
                                      input qo_curr,
                                      input qo_ex_rate,
                                      input qo_ex_rate2,
                                      input ' ',  /* BLANK EX_RATETYPE */
                                      input qo_exru_seq,
                                      input no)"""}
      end. /* IF use-log-acctg */

      end.
   end.   /* TRANSACTION */

   /* TRAILER */
   {gprun.i ""sqqomtc.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


end.
global_type = comment_type.

if cfexists and cf_cfg_strt_err = no then do:
   /* Close configurations*/
        
   {gprunmo.i &module  = "cf" &program = "cfcfclos.p"
      &param   = """(input cf_cfg_path, input cf_chr,
      cf_cfg_suf) """
   }
     

   /* Shut configurator*/
        
   {gprunmo.i &module   = "cf" &program  = "cfcfstop.p"}
     
end.

status input.
